//package com.example.demo;
//
//import jakarta.servlet.http.Cookie;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.BufferedOutputStream;
//import java.io.File;
//import java.io.IOException;
//import java.util.Arrays;
//import java.util.List;
//
//public class MVC_0724 {
//    package com.example.demo;
//
//import jakarta.servlet.http.Cookie;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//import org.apache.tomcat.util.http.fileupload.FileUtils;
//import org.springframework.boot.web.servlet.server.Session;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.BufferedOutputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.util.Arrays;
//import java.util.List;
//
//    @RestController
//    public class MVC_07_22_1 {
//        @RequestMapping("/sayhi")
//        public String methed() {
//            return "hello,Spring MVC";
//        }
//
//        @RequestMapping("/m1")
//        public String m1(String name){
//            return "接收参数name ="+name;
//        }
//        @RequestMapping("/m2")
//        public int m2(int a){
//            return a;
//        }
//        @RequestMapping("/m3")
//        public Object m3(String name,int age){
//            return name+age;
//        }
//        @RequestMapping("/m4")
//        public Person m4(Person p){
//            return p;
//        }
//        @RequestMapping("/m5")
//        public Object m5(@RequestParam(value = "na",required = false) String name){
//            return name;
//        }
//        @RequestMapping("/m6")
//        public String m6(String[] str){
//            return Arrays.toString(str);
//        }
//        @RequestMapping("m7")
//        public List<String> m7(@RequestParam List<String> list){
//            return list;
//        }
//        @RequestMapping("m8")
//        public String m8(@RequestBody Person person){
//            return person.toString();
//        }
//        @RequestMapping("m9/{id}/{name}")
//        public String m9(@PathVariable Integer id, @PathVariable("name")String usename){
//            return id+usename;
//        }
//        @RequestMapping("m10")
//        public String m9(@RequestPart("file") MultipartFile file) throws IOException {
//            String filename = file.getOriginalFilename();
//            System.out.println(filename);
//            //
//            BufferedOutputStream bufferedOutputStream = null;
//            try {
//                if (!file.isEmpty()){
//                    //注释这部分上传
////                byte[] bytes = file.getBytes();
////                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(
////                        new File("C:\\Users\\陆宇杰\\Pictures\\Screenshots\\test" + file.getOriginalFilename())));
////                bufferedOutputStream.write(bytes);
////                bufferedOutputStream.close();
//                    file.transferTo(new File("C:\\Users\\陆宇杰\\Pictures\\Screenshots"+"123321"));
//                }else {
//                    System.out.println("文件为空");
//                }
//            }catch (Exception e){
//                return "接收到的文件为+"+filename;
//            }
//
//
//            return "接收到的文件为+"+filename;
//        }
//        @RequestMapping("m11")
//        public String m11(HttpServletRequest request, HttpServletResponse response){
//            Cookie[] cookies = request.getCookies();
//            StringBuilder builder = new StringBuilder();
//            if(cookies != null){
//                for(Cookie ck:cookies){
//                    builder.append(ck.getName()+":"+ck.getValue());
//                }
//            }
//            return "Cookie信息:"+builder;
//        }
//        @RequestMapping("m12")
//        public String m12(@CookieValue("bite") String b){
//            return "bite"+b;
//        }
//        @RequestMapping("m13")
//        public String m13(HttpServletRequest request){
//            HttpSession session = request.getSession();
//            if(session != null){
//                session.setAttribute("usename","java");
//            }
//
//            return "session 存储成功";
//        }
//
//        @RequestMapping("m14")
//        public String m14(HttpServletRequest request){
//            HttpSession session = request.getSession(false);
//            String usename = null;
//            if (session != null && session.getAttribute("usename") != null) {
//                usename = (String) session.getAttribute("usename");
//            }
//            return "usename:"+usename;
//        }
//        @RequestMapping("m16")
//        public String m16(@SessionAttribute(value = "usename",required = false)String usename){
//            return "usename:"+usename;
//        }
//        @RequestMapping("m17")
//        public String m17(HttpSession session){
//            String usename = (String)session.getAttribute("usename");
//            return "usename："+usename;
//        }
//        @RequestMapping("m15")
//        public String m15(HttpServletRequest request,HttpServletResponse response){
//            String user = request.getHeader("User-Agent");
//            return user+":";
//        }
//        @RequestMapping("m18")
//        public String m18(@RequestHeader("user-agent")String useer){
//            return useer;
//        }
//    }
//
//
//}
